﻿<?php
class reply_process{

	private $db ;
	private $db_obj_reply ;

	function __construct( $db , $request = null ){
		
		$this->db = $db ;
		$this->db_obj_reply = new db_obj_reply( $db );

		$this->db_obj_reply->set( 'reply_time' , date( "Y-m-d H:i:s",time()+8*60*60 ) );

		if ( !empty($request) ){
			
			foreach( $request as $k => $v ){
	
				$this->db_obj_reply->set( $k , $v ); 
			}
		}
	}
	function set_reply_username( $username ){

		return $this->db_obj_reply->set( 'reply_username' , $username );
	}

	function save(){

		return $this->db_obj_reply->save();
	}
	function delete_by_no($no){

		$sql = "DELETE FROM reply WHERE reply_no =".$no ;
		$res = $this->db->query( $sql ); 
		if (PEAR::isError($res)) {
			throw new Exception( '删除出错'.$res->getMessage() );
		}
	}
	function delete_by_topic_no($topic_no){

		$sql = "DELETE FROM reply WHERE topic_no =".$topic_no ;
		$res = $this->db->query( $sql ); 
		if (PEAR::isError($res)) {
			throw new Exception( '删除出错'.$res->getMessage() );
		}
	}
	
    static function get_reply_topic_by_username($db,$username){
	
	    $sql = "SELECT * FROM topic,reply  WHERE reply_username ='$username' and topic.topic_no=reply.topic_no" ;
		$res = $db->query( $sql ); 
		if (PEAR::isError($res)) {

			throw new Exception( '获得topic列表出错'.$res->getMessage() );
		}

		if ( $res->NumRows() >= 1 ){
			
			$rows = $res->fetchAll(MDB2_FETCHMODE_ASSOC) ;
			return $rows ;
		
		}else{
			
			return false ;	
		}		
	}
}
?>
